package com.crazy.shell.provider.service.impl;

import com.alibaba.fastjson.JSON;
import com.crazy.shell.provider.entity.Company;
import com.crazy.shell.provider.entity.respority.Resume;
import com.crazy.shell.provider.mapper.CompanyMapper;
import com.crazy.shell.provider.service.ICompanyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.stereotype.Service;
import redis.clients.jedis.Jedis;

import java.util.List;

/**
 *
 * Company 表数据服务层接口实现类
 *
 */
@Service
public class CompanyServiceImpl implements ICompanyService {

    @Autowired
    private CompanyMapper companyMapper;

    @Autowired
    private MongoTemplate mongoTemplate;

    @Autowired
    private Jedis jedis;

    @Override
    public Company insert(Company company) {
        int row =  companyMapper.insert(company);
        if(row > 0){
            jedis.set("company"+company.getId(), JSON.toJSONString(company));
        }
        mongoTemplate.insert(new Resume(JSON.toJSONString(company)));
        return company;
    }

    @Override
    public List<Company> findList() {
        List<Company> all = companyMapper.selectAll();
        return all;
    }
}